import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const getComponent = (name, component) => () =>
    import (`@/views/${name}/${component}.vue`);
const myRouter = new Router({
    routes: [{
            path: '/login',
            name: 'login',
            component: getComponent('login', 'login')
        },
        {
            path: '/',
            redirect: '/login',
            component: getComponent('login', 'login')
        } ,{
          path: '/home',
          component: getComponent('layout', 'Layout'),
          children: [{
                  path: '/home',
                  component: getComponent('home', 'index'),
                  meta: {
                      title: 'home'
                  }
              },
              {
                  path: '/acceptOrder', //受理单处理
                  component: getComponent('acceptOrders', 'acceptOrder'),
                  meta: {
                      title: 'acceptOrder'
                  }
              },
              {
                  path: '/toLide',
                  component: getComponent('acceptOrders', 'toLide'),
                  meta: {
                      title: 'toLide'
                  }
              },
              {
                  path: '/receiptManagement',
                  component: getComponent('transport', 'receiptManagement'),
                  meta: {
                      title: 'receiptManagement'
                  }
              },
              {
                  path: '/transportLists',
                  component: getComponent('transport', 'transportLists'),
                  meta: {
                      title: 'transportLists'
                  }
              },
              {
                  path: '/serviceCarManagement',
                  component: getComponent('transport', 'serviceCarManagement'),
                  meta: {
                      title: 'serviceCarManagement'
                  }
              },
              {
                  path: '/sweepCodeBinding',
                  component: getComponent('transport', 'sweepCodeBinding'),
                  meta: {
                      title: 'sweepCodeBinding'
                  }
              },
              {
                  path: '/carTeam',
                  component: getComponent('carTeam', 'carTeam'),
                  meta: {
                      title: 'carTeam'
                  }
              },
              {
                  path: '/autoCar',
                  component: getComponent('carTeam', 'autoCar'),
                  meta: {
                      title: 'autoCar'
                  }
              },
              {
                  path: '/acceptStatement',
                  component: getComponent('financialControl', 'acceptStatement'),
                  meta: {
                      title: 'acceptStatement'
                  }
              },
              {
                  path: '/externalStatement',
                  component: getComponent('financialControl', 'externalStatement'),
                  meta: {
                      title: 'externalStatement'
                  }
              },
            //   下面的路由需要后期配置
            //   {
            //       path: '/formDesign',
            //       component: getComponent('formDesign', 'index'),
            //       meta: {
            //           title: 'formDesign'
            //       }
            //   },
            //   {
            //       path: '/permissionMenu',
            //       component: getComponent('permission', 'permission'),
            //       meta: {
            //           title: 'permissionMenu',
            //           roles: ['admin']
            //       }
            //   },
            //   {
            //       path: '/permissionBtn',
            //       component: getComponent('permission', 'permissionBtn'),
            //       meta: {
            //           title: 'permissionBtn',
            //       }
            //   },
              {
                  path: '/404',
                  component: getComponent('error', '404'),
                  meta: {
                      title: '404'
                  }
              },
              {
                  path: '/403',
                  component: getComponent('error', '403'),
                  meta: {
                      title: '403'
                  }
              }
          ]
      }, 
      
    ]
})

// //判断是否存在token
// myRouter.beforeEach((to, from, next) => {
//     NProgress.start()
//     if (to.path !== '/login' && !store.state.token) {
//         next('/login')
//         NProgress.done() // 结束Progress
//     } else {
//         next();
//     }
//     if (to.meta.roles) {
//         to.meta.roles.includes(...store.getters.roles) ? next() : next('/404')
//     } else {
//         next();
//     }
// })

// myRouter.afterEach(() => {
//     NProgress.done() // 结束Progress
// })
export default myRouter
